import { defineStore } from 'pinia';
import { ref } from 'vue';
import { setLocal, removeLocal } from '@/utils/localMethods';
// 用户信息存储
export const useUserStore = defineStore('user', () => {
	const token = ref();
	const userInfo = ref();
	const setToken = (tokenData: any) => {
		token.value = tokenData;
		setLocal('token', token.value);
	};
	const setUserInfo = (userInfoData: any) => {
		userInfo.value = userInfoData;
		setLocal('userInfo', userInfo.value);
	};

	const clearUserInfo = () => {
		token.value = '';
		userInfo.value = '';
		removeLocal('token');
		removeLocal('userInfo');
	};
	return { token, userInfo, setToken, setUserInfo, clearUserInfo };
});
